/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaRouter.java
 *
 * Created on 08/02/2012, 13:16:08
 */
package tsb.UI.Ventanas;

import java.awt.Image;
import java.awt.Toolkit;
import java.util.ArrayList;
import tsb.UI.PanelArrastrar.BotonPersonalizado;
import tsb.dominio.dispositivos.Dispositivo;
import tsb.dominio.dispositivos.coneccion.Router;
import tsb.dominio.interfaces.InterfaceDeConeccion;
import tsb.gestores.GestorDeDispositivos;

/**
 *
 * @author Fede
 */
public class VentanaRouter extends javax.swing.JFrame {
    private Router router;
    private ArrayList<InterfaceDeConeccion> listaInterfaces;
    private tsb.gestores.GestorDeDispositivos gestorDisp;
    private tsb.UI.PanelArrastrar.BotonPersonalizado btnPersonalizado;
    
    private tsb.UI.Paneles.ROUTER.PanelRouter panelRouter;

    /** Creates new form VentanaRouter */
    public VentanaRouter(String nombreAMostrar, tsb.gestores.GestorDeDispositivos gestorDisp, Dispositivo disp,tsb.UI.PanelArrastrar.BotonPersonalizado btnPersonalizado) {
        initComponents();
        
        this.panelRouter = new  tsb.UI.Paneles.ROUTER.PanelRouter(this);
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelRouter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(83, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(panelRouter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        
        
        
        
        router=(Router)disp;
        this.setTitle(router.getNombreAMostrar());
        this.gestorDisp=gestorDisp;
        listaInterfaces = new ArrayList<InterfaceDeConeccion>();
        this.btnPersonalizado=btnPersonalizado;
        this.setRouter(router);
        
    }
    
    public Image getIconImage()
     {
       Image retValue = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/tsb/UI/Imagenes/ROUTER_16x16.png"));
       return retValue;
    }
    
    public void setRouter(Router router)
    {
//        this.router=router;
//        this.panelRouter.setNombreAMostrar(this.router.getNombreAMostrar());
//        this.panelRouter.setEncendido(this.router.getEstado());
//        this.panelRouter.setHostName(this.router.getHostName());
//        if(this.router.getInterfaces() != null)
//        {
//             this.panelRouter.agregarInterfaces(router.getInterfaces());
//        }

    }

    public Router getRouter()
    {
//        this.router.setNombreAMostrar(this.panelRouter.getNombreAMostrar());
//        this.router.setEstado(this.panelRouter.getEncendido());
//        this.router.setHostName(this.panelRouter.getHostName());
//        //this.listaInterfaces=router.getInterfaces();
//
//        if(panelRouter.getPestañas()[0]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz1()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[1]!=false)
//            
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañainterfaz2()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[2]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz3()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[3]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz4()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[4]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz5()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[5]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz6()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[6]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz7()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[7]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz8()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[8]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz9()));
//            this.router.setInterfaces(listaInterfaces);
//        }
//        if(panelRouter.getPestañas()[9]!=false)
//        {
//            this.listaInterfaces.add(this.panelRouter.getInterfaz(this.panelRouter.getPanelPestañaInterfaz10()));
//            this.router.setInterfaces(listaInterfaces);
//        }

        return router;
    }

    public GestorDeDispositivos getGestorDisp() {
        return gestorDisp;
    }

    public void setGestorDisp(GestorDeDispositivos gestorDisp) {
        this.gestorDisp = gestorDisp;
    }

    public BotonPersonalizado getBtnPersonalizado() {
        return btnPersonalizado;
    }

    public void setBtnPersonalizado(BotonPersonalizado btnPersonalizado) {
        this.btnPersonalizado = btnPersonalizado;
    }
    
     private void agregarDisp()
    {
         Router router= this.getRouter();
         gestorDisp.actualizarDisp(router);
         btnPersonalizado.setText(router.getNombreAMostrar());
         this.btnPersonalizado.setVentanaAbierta(false);
         this.dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelBotones = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconImage(getIconImage());

        panelBotones.setBackground(new java.awt.Color(255, 255, 255));

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(258, Short.MAX_VALUE)
                .addComponent(btnAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar)
                .addContainerGap())
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnAceptar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(499, Short.MAX_VALUE)
                .addComponent(panelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        
        agregarDisp();
    }//GEN-LAST:event_btnAceptarActionPerformed

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JPanel panelBotones;
    // End of variables declaration//GEN-END:variables
}
